package com.czy.mapper;

import com.czy.dto.LoginDto;
import com.czy.dto.UserDto;
import com.czy.dto.UserPageDto;
import com.czy.entity.User;
import com.czy.vo.UserInfoVo;
import com.czy.vo.UserVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface UserMapper {

    /**
     * 查询所有用户内容
     * @return 返回用户信息
     */
    @Select("select id, username, password, name, phone, role, email, create_time, update_time " +
            "from user")
    public List<User> findAll();

    /**
     * 根据用户名和密码查询员工信息
     */
    @Select("select id, username ,password from user " +
            "where username = #{username}")
    public User selectByUsernameAndPassword(LoginDto loginDto);

    /**
     * 根据用户查询Id(登录)
     */
    @Select("select id,username,role from user where id = #{id}")
    public UserInfoVo LoginFindById(Integer id);

    /**
     * 分页查询用户
     */
    public List<User> list (UserPageDto pageDto);

    /**
     * 新增用户
     */
    @Insert("insert into user(username, password, name, phone, role, email, create_time, update_time) " +
            "values (#{username}, #{password}, #{name}, #{phone}, #{role}, #{email}, #{createTime}, #{updateTime})")
    public void insertUser(User user);

    /**
     * 修改用户
     */
    public void updateUser(User user);

    /**
     * 批量删除用户
     */
    public void deleteByIds(List<Integer> ids);

    /**
     *  根据id查询用户(查询回显)
     */
    @Select("select id, username, name, phone, role, email from user " +
            "where id = #{id}")
    UserVo selectById(Integer id);
}
